<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="姓名" prop="realName">
        <el-input
          v-model="queryParams.realName"
          placeholder="请输入姓名"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="职工号" prop="jobNumber">
        <el-input
          v-model="queryParams.jobNumber"
          placeholder="请输入职工号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <template>
      <el-tabs v-model="activeName" @tab-click="handleClick">
        <el-tab-pane label="未回复" name="1">
          <el-table v-loading="loading" :data="medicalFeeQueryList" @selection-change="handleSelectionChange">
            <!--<el-table-column type="selection" width="55" align="center" />
            <el-table-column label="ID" align="center" prop="id" />-->
            <el-table-column label="姓名" align="center" prop="params.realName" />
            <el-table-column label="工号" align="center" prop="params.jobNumber" />
            <el-table-column label="所属工会" align="center" prop="params.deptName" />
            <el-table-column label="质疑内容" align="center" prop="queryContent" />
            <el-table-column label="提交时间" align="center" prop="createTime" />
            <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
              <template slot-scope="scope">
                <el-button
                  size="mini"
                  type="text"
                  icon="el-icon-view"
                  @click="detail(scope.row)"
                >详情</el-button>
              </template>
            </el-table-column>
          </el-table>
          <pagination
            v-show="total>0"
            :total="total"
            :page.sync="queryParams.pageNum"
            :limit.sync="queryParams.pageSize"
            @pagination="getList"
          />
        </el-tab-pane>

        <el-tab-pane label="已回复" name="0">
          <el-table v-loading="loading" :data="medicalFeeQueryList" @selection-change="handleSelectionChange">
            <!--<el-table-column type="selection" width="55" align="center" />
            <el-table-column label="ID" align="center" prop="id" />-->
            <el-table-column label="姓名" align="center" prop="params.realName" />
            <el-table-column label="工号" align="center" prop="params.jobNumber" />
            <el-table-column label="所属工会" align="center" prop="params.deptName" />
            <el-table-column label="质疑内容" align="center" prop="queryContent" />
            <el-table-column label="提交时间" align="center" prop="createTime" />
            <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
              <template slot-scope="scope">
                <el-button
                  size="mini"
                  type="text"
                  icon="el-icon-view"
                  @click="detail(scope.row)"
                >详情</el-button>
              </template>
            </el-table-column>
          </el-table>
          <pagination
            v-show="total>0"
            :total="total"
            :page.sync="queryParams.pageNum"
            :limit.sync="queryParams.pageSize"
            @pagination="getList"
          />

        </el-tab-pane>
      </el-tabs>
    </template>



    <!-- 添加或修改医疗费用质疑记录对话框 -->
    <!--<el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="医疗费用id" prop="medicalFeeId">
          <el-input v-model="form.medicalFeeId" placeholder="请输入医疗费用id" />
        </el-form-item>
        <el-form-item label="小程序用户id" prop="miniUserId">
          <el-input v-model="form.miniUserId" placeholder="请输入小程序用户id" />
        </el-form-item>
        <el-form-item label="质疑内容">
          <editor v-model="form.queryContent" :min-height="192"/>
        </el-form-item>
        <el-form-item label="质疑附件" prop="queryAttachment">
          <el-input v-model="form.queryAttachment" placeholder="请输入质疑附件" />
        </el-form-item>
        <el-form-item label="是否回复 0是 1否" prop="isReply">
          <el-input v-model="form.isReply" placeholder="请输入是否回复 0是 1否" />
        </el-form-item>
        <el-form-item label="回复附件" prop="replyAttachment">
          <el-input v-model="form.replyAttachment" placeholder="请输入回复附件" />
        </el-form-item>
        <el-form-item label="备注" prop="remark">
          <el-input v-model="form.remark" placeholder="请输入备注" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>-->
  </div>
</template>

<script>
import { listMedicalFeeQuery, getMedicalFeeQuery, delMedicalFeeQuery, addMedicalFeeQuery, updateMedicalFeeQuery } from "@/api/query/medicalFeeQuery";
import { selectSecondDeptList } from "@/api/system/dept";

export default {
  name: "MedicalFeeQuery",
  data() {
    return {
      // 遮罩层
      loading: true,
      //tab默认选择值
      activeName: '1',
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 医疗费用质疑记录表格数据
      medicalFeeQueryList: [],
      //单位（二级工会）
      deptList:[],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        realName: null,
        jobNumber: null,
        deptId: null,
        status: null,
        isReply:"1"
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        medicalFeeId: [
          { required: true, message: "医疗费用id不能为空", trigger: "blur" }
        ],
        miniUserId: [
          { required: true, message: "小程序用户id不能为空", trigger: "blur" }
        ],
      }
    };
  },
  created() {
    this.getList();
    this.selectSecondDeptList();
  },
  methods: {
    //tab 切换
    handleClick(tab, event) {
      console.log(tab.name);
      this.queryParams.isReply=tab.name;
      this.activeName=tab.name;
      //this.medicalFeeQueryList=[];
      this.getList();
      console.log("=="+this.queryParams.isReply);
    },
    /** 查询医疗费用质疑记录列表 */
    getList() {
      this.loading = true;
      listMedicalFeeQuery(this.queryParams).then(response => {
        this.medicalFeeQueryList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    /** 详情 */
    detail: function(row) {
      const id = row.id;
      //console.log(id);
     this.$router.push("/query/medicalFeeQuery-detail/detail/"+id);
    },
    selectSecondDeptList() {
      selectSecondDeptList().then(response => {
        this.deptList = response.data;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        medicalFeeId: null,
        miniUserId: null,
        queryContent: null,
        queryAttachment: null,
        isReply: null,
        replyAttachment: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        remark: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加医疗费用质疑记录";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getMedicalFeeQuery(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改医疗费用质疑记录";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateMedicalFeeQuery(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addMedicalFeeQuery(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除医疗费用质疑记录编号为"' + ids + '"的数据项？').then(function() {
        return delMedicalFeeQuery(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('business/medicalFeeQuery/export', {
        ...this.queryParams
      }, `medicalFeeQuery_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
